package com.tourism.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tourism.dao.AttractionEvaluationDao;
import com.tourism.dao.AttractionOrderDao;
import com.tourism.entity.AttractionEvaluation;
import com.tourism.entity.AttractionEvaluationQuery;
import com.tourism.service.AttractionEvaluationService;
import com.tourism.util.IdUtils;
import com.tourism.util.SystemHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Description
 * @Author z
 * @Date 2021-05-01 17:02
 */
@Service
public class AttractionEvaluationServiceImpl implements AttractionEvaluationService {

    @Autowired
    private AttractionEvaluationDao attractionEvaluationDao;
    @Autowired
    private AttractionOrderDao attractionOrderDao;
//新增景点评价
    @Override
    public boolean addAttractionEvaluation(AttractionEvaluation attractionEvaluation) {
        attractionEvaluation.init();
        attractionEvaluation.setEvaluationUser(SystemHelper.getUserId());
//        跟新景点订单评价状态
        attractionOrderDao.updateEvaluation(true, attractionEvaluation.getAttractionOrderId());

        attractionEvaluationDao.addAttractionEvaluation(attractionEvaluation);
        return true;
    }

    @Override
    public AttractionEvaluation getAttractionEvaluationById(Long id) {
        return attractionEvaluationDao.getAttractionEvaluationById(id);
    }
    @Override
    public AttractionEvaluation getAttractionEvaluationByOrderId(Long orderId) {
        return attractionEvaluationDao.getAttractionEvaluationByOrderId(orderId);
    }

    @Override
    public PageInfo<AttractionEvaluation> getAttractionEvaluationList(AttractionEvaluationQuery query) {
        PageHelper.startPage(query.getPageNum(), query.getPageSize());
        List<AttractionEvaluation> AttractionList = attractionEvaluationDao.getAttractionEvaluationList(query);
        PageInfo<AttractionEvaluation> result = new PageInfo<>(AttractionList);
        return result;
    }
}
